﻿using JNPF.Basics.Models.Extend.Dtos.DocumentPreview;
using JNPF.Utils;
using System.Collections.Generic;

namespace JNPF.Basics.Logic.Extend.DocumentPreview
{
    /// <summary>
    /// 文件预览
    /// </summary>
    public class DocumentPreviewBll
    {
        public List<DocumentPreviewListOutput> GetList(KeywordInput input)
        {
            var filePath = ConfigurationKey.DocumentPreviewFilePath;
            var files = FileHelper.GetAllFiles(filePath);
            List<FileModel> data = new List<FileModel>();
            if (files != null)
            {
                for (int i = 0; i < files.Count; i++)
                {
                    var item = files[i];
                    FileModel fileModel = new FileModel();
                    fileModel.FileId = i.ToString();
                    fileModel.FileName = item.Name;
                    fileModel.FileType = FileHelper.GetFileType(item);
                    fileModel.FileSize = FileHelper.GetFileSize(item.FullName).ToString();
                    fileModel.FileTime = item.LastWriteTime;
                    data.Add(fileModel);
                }
                data = data.FindAll(x => "xlsx".Equals(x.FileType) || "xls".Equals(x.FileType) || "docx".Equals(x.FileType) || "doc".Equals(x.FileType) || "pptx".Equals(x.FileType) || "ppt".Equals(x.FileType));
            }
            if (!input.keyword.IsNullOrEmpty())
            {
                data = data.FindAll(x => x.FileName.Contains(input.keyword));
            }
            var output = data.MapToList<DocumentPreviewListOutput>();
            return output;
        }



    }
}
